package com.zjcloud.academic.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zjcloud.common.annotation.Anonymous;
import com.zjcloud.common.core.controller.BaseController;
import com.zjcloud.common.core.domain.AjaxResult;
import com.zjcloud.common.core.page.TableDataInfo;
import com.zjcloud.academic.service.IJwglSchoolInfoService;
import com.zjcloud.academic.domain.JwglSchoolInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学校信息Controller
 * 
 * @author zjcloud
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/jwgl/schoolinfo")
public class JwglSchoolInfoController extends BaseController
{
    @Autowired
    private IJwglSchoolInfoService jwglSchoolInfoService;

    /**
     * 查询学校信息列表（分页）
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(JwglSchoolInfo jwglSchoolInfo, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize)
    {
        // 直接从请求参数获取分页参数
        PageHelper.startPage(pageNum, pageSize);
        List<JwglSchoolInfo> list = jwglSchoolInfoService.selectJwglSchoolInfoList(jwglSchoolInfo);
        return getDataTable(list);
    }
    
    /**
     * 查询学校信息列表（不分页）
     */
    @GetMapping("/list/all")
    public AjaxResult listAll(JwglSchoolInfo jwglSchoolInfo)
    {
        List<JwglSchoolInfo> list = jwglSchoolInfoService.selectJwglSchoolInfoList(jwglSchoolInfo);
        return AjaxResult.success(list);
    }
    
    /**
     * 根据ID查询学校信息
     */
    @GetMapping("/query/{schoolId}")
    public AjaxResult getInfo(@PathVariable("schoolId") Long schoolId)
    {
        return AjaxResult.success(jwglSchoolInfoService.selectJwglSchoolInfoById(schoolId));
    }
    
    /**
     * 根据学校代码查询学校信息
     */
    @GetMapping("/queryByCode/{schoolCode}")
    public AjaxResult getInfoByCode(@PathVariable("schoolCode") String schoolCode)
    {
        return AjaxResult.success(jwglSchoolInfoService.selectJwglSchoolInfoByCode(schoolCode));
    }
    
    /**
     * 查询正常状态的学校列表
     */
    @GetMapping("/active")
    public AjaxResult getActiveSchools()
    {
        return AjaxResult.success(jwglSchoolInfoService.selectActiveSchools());
    }
    
    /**
     * 新增学校信息
     */
    @PostMapping("/save")
    public AjaxResult add(@RequestBody JwglSchoolInfo jwglSchoolInfo)
    {
        // 设置创建人和更新人信息
        jwglSchoolInfo.setCreateBy(getUsername());
        jwglSchoolInfo.setUpdateBy(getUsername());
        return toAjax(jwglSchoolInfoService.insertJwglSchoolInfo(jwglSchoolInfo));
    }
    
    /**
     * 修改学校信息
     */
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody JwglSchoolInfo jwglSchoolInfo)
    {
        // 设置更新人信息
        jwglSchoolInfo.setUpdateBy(getUsername());
        return toAjax(jwglSchoolInfoService.updateJwglSchoolInfo(jwglSchoolInfo));
    }
    
    /**
     * 删除学校信息
     */
    @DeleteMapping("/delete/{schoolIds}")
    public AjaxResult remove(@PathVariable Long[] schoolIds)
    {
        return toAjax(jwglSchoolInfoService.deleteJwglSchoolInfoByIds(schoolIds));
    }
}